package com.ysxsoft.wdg.ui.activity.my;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.TextView;
import com.ysxsoft.wdg.R;
import com.ysxsoft.wdg.base.BaseActivity;
import com.ysxsoft.wdg.bean.BaseBean;
import com.ysxsoft.wdg.bean.UserInfoBean;
import com.ysxsoft.wdg.net.CallbackCode;
import com.ysxsoft.wdg.ui.activity.login.ForgetPswActivity;
import com.ysxsoft.wdg.util.ViewUtils;
import com.ysxsoft.wdg.util.sp.SharePrefUtils;

import butterknife.BindView;
import butterknife.OnClick;
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

public class SafeActivity extends BaseActivity {

    private UserInfoBean infoBean;

    public static void start(Context context){
        Intent intent = new Intent(context,SafeActivity.class);
        context.startActivity(intent);
    }


    @BindView(R.id.topView)
    View topView;
    @BindView(R.id.title_content)
    TextView titleContent;
    @BindView(R.id.tv_mobie)
    TextView tvMobie;
    @BindView(R.id.tv_zfb)
    TextView tvZfb;


    private String uid= "";

    @Override
    protected int getLayoutId() {
        return R.layout.activity_safe;
    }

    @Override
    protected void initData() {
        initStatusBar(topView,false);
        titleContent.setText("账号与安全");

    }

    @Override
    protected void onResume() {
        super.onResume();
        uid = SharePrefUtils.getUserId();

        mApiHelper.getAccountInfo(uid, new Observer<BaseBean<UserInfoBean>>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(BaseBean<UserInfoBean> baseBean) {
                if (baseBean.getCode().equals(CallbackCode.SUCCESS)){

                    infoBean = baseBean.getData();
                    tvMobie.setText(ViewUtils.changeMobile(infoBean.getMobile()));
                    tvZfb.setText(ViewUtils.changeMobile(infoBean.getAlicode()));

                }

            }

            @Override
            public void onError(Throwable e) {

            }

            @Override
            public void onComplete() {

            }
        });
    }

    @Override
    protected void setListener() {

    }

    @OnClick({R.id.title_finish, R.id.ll_mobie, R.id.ll_zfb, R.id.ll_psw})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.title_finish:
                finish();
                break;
            case R.id.ll_mobie://修改手机号
                ModifyMobile1Activity.start(mContext,infoBean.getMobile());
                break;
            case R.id.ll_zfb://修改支付宝账号
                BindZfbActivity.start(mContext,infoBean.getAlicode());
                break;
            case R.id.ll_psw://修改登录密码
                ForgetPswActivity.start(this,1);
                break;
        }
    }
}
